<template>
  <div class="container">
    <div>学校的名称:{{ name }}</div>
    <h1>学校的地址:{{ address }}</h1>
  </div>
</template>
<script>
import pubsub from "pubsub-js";
export default {
  name: "School",
  props: ["getSchoolName"],
  data() {
    return {
      name: "前端学院",
      address: "火星",
    };
  },
  methods: {
    demo(msgName, data) {
      console.log("hello,接收到了从student发过来额消息了", data);
    }
  },
  mounted() {
    // this.$bus.$on('hello',(data) => {
    //   console.log("我是school组件，我收到了student传过来的数据",data)
    // })
    //订阅消息
    this.pubId = pubsub.subscribe("hello", this.demo);
  },
  //取消消息订阅
  beforeDestroy() {
    // this.$bus.off('hello')
    pubsub.unsubscribe(this.pubId);
  },
};
</script>
<style scoped>
.container {
  background-color: orange;
}
</style>
